<template>
	<view class="content">
		<!-- 头部 -->
		<header-navbar class="headerNavbar"></header-navbar>
		<view class="allContainer" :style="{top:navHeaderHeight+'px'}">
			<!-- 轮播图 -->
			<view class="swiperContainer">
				<swiper class="swiperBox" indicator-dots="true" autoplay="true" interval="3000" duration="1000" circular="true">
					<swiper-item>
						<image class="swiperItemImg" src="../../static/images/swiper1.jpg" mode="aspectFill"></image>
					</swiper-item>
					<swiper-item>
						<image class="swiperItemImg" src="../../static/images/swiper2.jpg" mode="aspectFill"></image>
					</swiper-item>
					<swiper-item>
						<image class="swiperItemImg" src="../../static/images/swiper3.jpg" mode="aspectFill"></image>
					</swiper-item>
				</swiper>
			</view>
			<view class="container">
				<view class="safeArea">
					<!-- 导航区 -->
					<view class="navbarBox">
						<view class="navbarContainer">
							<navigator class="orderNow" url='../menu/menu' open-type='switchTab'>
								<view class="orderNowTip">
									自提/外卖
								</view>
								<view class="orderNowTitle">
									<text>现在下单</text>
									<text class="ordersubtitle">ORDER NOW</text>
								</view>
								<view class="orderNowImg">
									<image class="orderLogo" src="../../static/images/orderLogo.png" mode="scaleToFill"></image>
								</view>
							</navigator>
							<!-- 特惠 -->
							<view class="preference">
								<!-- 咖啡钱包 -->
								<navigator class="walletBox" url='../balance/balance'>
									<view class="walletTitle">
										<text>咖啡钱包</text>
										<text class="walletSubtitle">COFFEE WALLET</text>
										<text class="walletPre">充2赠1</text>
									</view>
									<image class="walletLogo" src="../../static/images/orderLogo.png" mode="scaleToFill"></image>
								</navigator>
								<!-- 优惠券 -->
								<navigator class="couponBox" url='../coupon/coupon'>
									<view class="couponTitle">
										<text>优惠券</text>
										<text class="couponsubtitle">VALUE VOUCHER</text>
									</view>
								</navigator>
							</view>
						</view>
					</view>
					<!-- 今日特价 -->
					<view class="todayGood">
						<view class="todayGoodsTitle">
							<text>今日特价</text>
						</view>
						<view class="todayGoodsBox">
							<block v-for="(item,index) in todayGood" :key="index">
								<navigator class="todayGoodsItem" url=''>
									<image :src="item.goodsImg" mode="aspectFill"></image>
									<view class="todayGoodsItemBox">
										<text class="todayGoodsItemBoxTitle">{{item.goodsName}}</text>
										<text class="todayGoodsItemBoxSubtitle">{{item.goodsEngName}}</text>
										<view class="todayGoodsItemBoxPrice">
											<text class="todayGoodsItemBoxNewPrice">￥{{item.midPrice}}</text>
											<text class="todayGoodsItemBoxOldPrice">￥{{item.maxPrice}}</text>
										</view>
									</view>
								</navigator>
							</block>
						</view>
					</view>
					<!-- 新品资讯 -->
					<view class="news">
						<view class="newsBox">
							<text class="newsBoxTitle">新鲜事</text>
							<image src="../../static/images/swiper1.jpg" mode=""></image>
						</view>
					</view>
					<!-- 精品推荐 -->
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import HeaderNavbar from '../../components/HeaderNavbar.vue';
	import { navHeaderHeight } from '../../assets/js/navHeaderHeight.js';
	import { _get } from '../../assets/js/req.js';
	import { url } from '../../assets/js/baseUrl.js';
	export default {
		name: 'index',
		data() {
			return {
				navHeaderHeight: null, //自定义导航栏高度(用于填充防止页面塌陷)
				todayGood: null, //渲染到view的商品数据数组
			}
		},
		components: {
			HeaderNavbar,
		},
		methods: {
			//数据列表请求
			//调用封装好的请求
			getGoodsList() {
				// console.log(_post);
				//重定义地址(要用新变量名去接)
				let urls = url + '/todayGood'
				_get(urls).then((res) => {
					// console.log(res); //查看返回结果
					//接取所有商品数据
					this.todayGood = res.data.todayGood
					// console.log(this.todayGood); 
					//分离每项(把原数组内容分离)
					// for(let goodsItem of goodList){
					// 	//把分离好的每一项数据放入要显示到页面的商品数组
					// 	// 并且只要推荐的前3项
					// 	console.log(goodsItem);
					// 	if(goodsItem.name=="人气top"){
					// 		console.log(1111);
							
					// 	}
					// }

				})
			}
		},
		created() {
			var that = this;
			that.navHeaderHeight = navHeaderHeight
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.getGoodsList();
			// console.log(this.goodsList.value);
			// console.log(a);
			// this.getImg();
		},
		onReady: function() {
			// this.getGoodsList();
			// console.log(a);
			// console.log(1);
		}
	}
</script>
<style lang="scss">
	@import '@/assets/scss/mixin.scss';
	@import '@/assets/scss/config.scss';

	.content {
		@include flex(center, center);
		flex-direction: column;
		background-color: #FFF;

		.headerNavbar {
			@include position(relative);
			z-index: 10000;
			box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, .1);
			text-align: center;
			// margin-top: 44rpx;
		}

		.allContainer {
			width: 100%;
			position: relative;
			left: 0;

			.swiperContainer {
				width: 100%;

				.swiperBox {
					width: 100%;
					height: 400rpx;

					.swiperItemImg {
						width: 100%;
						height: 100%;
					}
				}
			}

			.container {
				//包含所有内容的主容器

				background-color: aliceblue;

				.safeArea {
					width: 94%;
					height: 100%;
					margin: 12rpx auto 0;

					//导航(现在下单...)
					.navbarContainer {
						background-color: #FFF;
						height: 350rpx;
						display: flex;
						margin-bottom: 20rpx;
						box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, .1);
						padding: 10rpx 10rpx 0rpx 10rpx;
						@include border-radius(20rpx, 20rpx, 20rpx, 20rpx) // 现在下单

						.orderNow {
							width: 45%;
							height: 330rpx;
							background-color: wheat;
							display: flex;
							flex-direction: column;
							position: relative;
							@include border-radius(10rpx, 0, 0, 10rpx) // padding: 2rpx;

							.orderNowTip {
								font-size: $fontE;
								color: white;
								right: 0;
								text-align: right;
								@include bgImg(100%, 39rpx, '../../static/images/orderNowImg.png');
								background-position: right;
							}

							.orderNowTitle {
								width: 200rpx;
								height: 100rpx;
								margin: 20rpx 0 0 30rpx;
								font-size: $fontC;

								.ordersubtitle {
									@include fontStyle();
								}
							}

							.orderNowImg {
								width: 100%;
								height: 160rpx;

								.orderLogo {
									@include navbarLogo(160rpx, 160rpx, 0, 0, 0, 140rpx);
								}
							}
						}

						//特惠
						.preference {
							width: 55%;
							height: 330rpx;
							display: flex;
							flex-direction: row-reverse;
							flex-wrap: wrap;

							.walletBox {
								width: 97%;
								height: 52%;
								background-color: wheat;
								margin: 0 0 3%;
								display: flex;

								@include border-radius(0, 10rpx, 0, 0) .walletTitle {
									width: 56%;
									height: 100%;
									margin: 0 0 0 20rpx;
									font-size: $fontC;

									.walletSubtitle {
										@include fontStyle($fontE);
									}

									.walletPre {
										@include fontStyle($fontF, red);
									}
								}

								.walletLogo {
									@include navbarLogo(130rpx, 130rpx, 20rpx, 0, 0, 20rpx);
								}
							}

							.couponBox {
								padding-top: 6rpx;
								width: 97%;
								height: 43%;
								background-color: wheat;

								@include border-radius(0, 0, 10rpx, 0) .couponTitle {
									width: 220rpx;
									height: 90rpx;
									margin: 14rpx;
									font-size: $fontC;
								}

								.couponsubtitle {
									@include fontStyle($fontE);
								}
							}
						}
					}

					//今日特价
					.todayGood {
						background-color: #FFF;
						padding-top: 10rpx;
						width: 100%;
						box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, .1);

						@include border-radius(20rpx, 20rpx, 20rpx, 20rpx) .todayGoodsTitle {
							width: 100%;
							height: 60rpx;
							padding: 0 0 0 20rpx;
							@include fontStyle($fontD, black);
						}

						.todayGoodsBox {
							width: 100%;
							// @include 
							height: 350rpx;
							display: flex;
							flex-direction: row;
							justify-content: space-evenly;
							margin-bottom: 10rpx;

							//产品的每一项
							.todayGoodsItem {
								width: 30%;
								height: 330rpx;
								border-radius: 20rpx;
								display: flex;
								flex-direction: column;
								text-align: center;
								border: 2rpx solid #E8E8E8;

								image {
									width: 100%;
									height: 55%;
									border-radius: 20rpx 20rpx 0 0;
								}

								.todayGoodsItemBox {
									width: 100%;
									height: 45%;
									background-color: $colorF;
									border-radius: 0 0 20rpx 20rpx;

									.todayGoodsItemBoxTitle {
										padding-top: 4rpx;
										width: 100%;
										display: block;
										font-size: $fontE;
										margin-bottom: 10rpx;
									}

									.todayGoodsItemBoxSubtitle {
										width: 100%;
										display: block;
										@include fontStyle($fontG, $colorD);
										margin-bottom: 10rpx;
									}

									.todayGoodsItemBoxPrice {
										width: 100%;
										margin-bottom: 10rpx;
										.todayGoodsItemBoxNewPrice {
											display: inline-block;
											@include fontStyle($fontF, $colorB);

											&:after {
												content: '|';
												padding: 0 10rpx;
											}
										}

										.todayGoodsItemBoxOldPrice {
											display: inline-block;
											@include fontStyle($fontG, $colorC);
										}

									}

								}
							}
						}
					}

					//新鲜事
					.news {
						background-color: #FFFFFF;
						width: 100%;
						margin: 20rpx auto;
						@include border-radius(20rpx, 20rpx, 20rpx, 20rpx) box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, .1);

						.newsBox {
							padding: 10rpx;

							.newsBoxTitle {
								display: inline-block;
								@include fontStyle($fontD, black);
								padding: 0 0 0 20rpx;
							}

							image {
								width: 100%;
								height: 410rpx;
								@include border-radius(10rpx, 10rpx, 10rpx, 10rpx)
							}
						}
					}
				}
			}
		}


	}
</style>
